package Classic150;

public class Z字形变换 {
    /*
        找规律
     */
    public String convert(String s, int numRows) {
        if (numRows == 1) return s;
        StringBuilder res = new StringBuilder();
        int[] skipNums = new int[numRows];
        for (int i = 0; i < numRows - 1; i++) skipNums[i] = (numRows - i - 1) * 2;
        skipNums[numRows - 1] = (numRows - 1) * 2;
        for (int i = 0; i < numRows; i++) {
            int cur = i;
            int index = i;
            while (cur < s.length()) {
                res.append(s.charAt(cur));
                cur += skipNums[index];
                index = numRows - index - 1;
            }
        }
        return res.toString();
    }
}
